<template>
  <div class="app-container">
    <h4 class="form-header h4">基本信息</h4>
    <el-form ref="form" :model="form" label-width="80px">
      <el-row>
        <el-col :span="4" :offset="2">
          <el-form-item label="姓名" prop="realName">
            <!--  <el-input v-model="form.realName" disabled />-->
            {{form.realName}}
          </el-form-item>
        </el-col>
        <el-col :span="4" :offset="2">
          <el-form-item label="工号" prop="jobNumber">
             <!-- <el-input  v-model="form.jobNumber" disabled />-->
            {{form.jobNumber}}
          </el-form-item>
        </el-col>
        <el-col :span="4" :offset="2">
          <el-form-item label="工会" >
            <!-- <el-input  v-model="form.jobNumber" disabled />-->
            {{form.params != null? form.params.deptName:""}}
          </el-form-item>
        </el-col>
        <el-col :span="4" :offset="2">
          <el-form-item label="单位" prop="jobNumber">
            <!-- <el-input  v-model="form.jobNumber" disabled />-->
            {{form.szdwmc}}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <h4 class="form-header h4">质疑信息</h4>
    <el-form ref="query" :model="query" label-width="80px">
      <el-row>
        <el-col :span="24" :offset="2">
          <el-form-item label="内容">
            {{query.queryContent}}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24" :offset="2">
        <el-form-item label="附件" prop="jobNumber">
            <el-image v-for="url in queryAttachment" :key="url"
              style="width: 100px; height: 100px;padding-right: 5px;"
              :src="url"
              :preview-src-list="queryAttachment"
              fit="fill"></el-image>
        </el-form-item>
      </el-col>
      </el-row>
      <el-row>
        <el-col :span="4" :offset="2">
          <el-form-item label="提交时间">
            {{query.createTime}}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <h4 class="form-header h4">回复信息</h4>
    <el-form ref="query" :model="query" label-width="80px">
      <el-row>
        <el-col :span="24" :offset="2">
          <el-form-item label="内容">
            {{query.replyContent}}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24" :offset="2">
          <el-form-item label="附件" prop="jobNumber">
            <el-image v-for="url in replyAttachment" :key="url"
                      style="width: 100px; height: 100px;padding-right: 5px;"
                      :src="url"
                      :preview-src-list="replyAttachment"
                      fit="fill"></el-image>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="4" :offset="2">
          <el-form-item label="审定自付费金额（元）" >
            {{query.auditedDeductible}}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-form label-width="100px">
      <el-form-item style="text-align: center;margin-left:-120px;margin-top:30px;">
        <el-button type="primary" @click="reply()"  v-hasPermi="['business:medicalFeeQuery:reply']">回复</el-button>
        <el-button @click="close()">返回</el-button>
      </el-form-item>
    </el-form>


    <el-dialog title="质疑回复" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="formReply" :rules="rules" label-width="130px">
        <el-form-item label="回复内容" prop="replyContent">
          <el-input v-model="formReply.replyContent" placeholder="请输入回复内容" type="textarea" />
        </el-form-item>
        <el-form-item label="审定自付费金额" prop="auditedDeductible">
          <el-input v-model="formReply.auditedDeductible" placeholder="请输入审定自付费金额" />
        </el-form-item>
        <el-form-item label="公费医疗报销凭证" prop="queryAttachment">
          <el-upload
            :action="uploadFileUrl"
            :headers="headers"
            :limit="1"
            :file-list="fileList"
            :on-success="handleSuccess"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>
          <el-dialog :visible.sync="dialogVisible">
            <img width="100%" :src="dialogImageUrl" alt="">
          </el-dialog>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {  getMedicalFeeQuery,reply } from "@/api/query/medicalFeeQuery";
import { getToken } from "@/utils/auth";
export default {
  name: "medicalFeeQueryDetail",
  data() {
    return {
      // 是否显示弹出层
      open: false,
       // 遮罩层
      loading: true,
      // 分页信息
      total: 0,
      pageNum: 1,
      pageSize: 10,
      // 用户信息
      form: {},
      //质疑信息
      query:{},
      queryAttachment:[],
      replyAttachment:[],
      //回复信息
      formReply:{},
      // 表单校验
      rules: {
        replyContent: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        auditedDeductible: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
      },
      dialogImageUrl: '',
      dialogVisible: false,
      uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      fileList:[],
      fileOne:{
        name:'',
        url:''
      },
      managPictures:[],
      managPicture:{
        id:'',
        pictureInforId:'',
        url:'',
        serialNumber:''
      },
      pictureUrls:[]
    };
  },
  created() {
    this.getMedicalFeeQuery();
    /*const id = this.$route.params && this.$route.params.id;
    if (id) {
      this.loading = true;
      this.formReply.id=id;
      getMedicalFeeQuery(id).then((response) => {
        console.log(response.data);
        this.form = response.data.params.sysMiniUser;
        this.query= response.data;
        const queryAttachment1 = response.data.queryAttachment.split(",");
        for(var num=0;num<queryAttachment1.length;num++){
          this.queryAttachment.push(process.env.VUE_APP_BASE_API +queryAttachment1[num]);
        }
        const replyAttachment1 = response.data.replyAttachment.split(",");
        for(var num=0;num<replyAttachment1.length;num++){
          this.replyAttachment.push(process.env.VUE_APP_BASE_API +replyAttachment1[num]);
        }
        this.loading = false;
      });
    }*/
  },
  methods: {
    getMedicalFeeQuery(){
      const id = this.$route.params && this.$route.params.id;
      if (id) {
        this.loading = true;
        this.formReply.id=id;
        getMedicalFeeQuery(id).then((response) => {
          console.log(response.data);
          this.form = response.data.params.sysMiniUser;
          this.query= response.data;
          const queryAttachment1 = response.data.queryAttachment.split(",");
          for(var num=0;num<queryAttachment1.length;num++){
            this.queryAttachment.push(process.env.VUE_APP_BASE_API +queryAttachment1[num]);
          }
          const replyAttachment1 = response.data.replyAttachment.split(",");
          for(var num=0;num<replyAttachment1.length;num++){
            this.replyAttachment.push(process.env.VUE_APP_BASE_API +replyAttachment1[num]);
          }
          this.loading = false;
        });
      }
    },
    /** 提交按钮 */
    submitForm() {
      console.log(this.formReply);
      this.$refs["form"].validate(valid => {
        if (valid) {
          reply(this.formReply).then(response => {
            //this.msgSuccess("回复成功");
            this.open = false;
            this.getMedicalFeeQuery();
           // this.getList();
          });
        }
      });
    },
    handleRemove(file, fileList) {
      console.log(fileList);
      console.log(fileList.length);
      this.pictureUrls = [];
     /* if (this.form.id != undefined) {
        for (var i = 0; i < fileList.length; i++) {
          this.pictureUrls.push(fileList[i].url.replace(process.env.VUE_APP_BASE_API,""));
        }
      } else {*/
        for (var i = 0; i < fileList.length; i++) {
          this.pictureUrls.push(fileList[i].response.fileName);
        }
      //}
      this.formReply.replyAttachment=this.pictureUrls.toString();
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleSuccess(response, file, fileList){
      console.log("response="+response.fileName);
      this.pictureUrls.push(response.fileName);
      this.formReply.replyAttachment=this.pictureUrls.toString();
      console.log("responsefileList.length="+fileList.length);
    },
    reply(){
      console.log("1111");
        this.open =true;
    },
    cancel() {
      this.open = false;
    },
    /** 关闭按钮 */
    close() {
      const obj = { path: "/query/medicalFeeQuery" };
      this.$tab.closeOpenPage(obj);
    },
  },
};
</script>
